﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using vgo_vs01.Models.KetNoi;
using vgo_vs01.Models.DoiTuong;
using vgo_vs01.Models;

namespace vgo_vs01.Controllers
{
    public class DaoCuController : Controller
    {
        //
        // GET: /DaoCu/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult TaoDaoCu()
        {
            VatPhamModels VpMd = new VatPhamModels();
            ViewData["dsvp"] = new SelectList(VpMd.LayVatPham(), "MaVatPham", "TenVatPham");
            ThanhVienModels TvMd = new ThanhVienModels();
            ViewData["dstv"] = new SelectList(TvMd.laydstv(), "MaThanhVien", "HoTen");
            return View();
        }
        [HttpPost]
        public ActionResult TaoDaoCu(int dsvp, int soluong, string trangthai, int dstv, string txtguiden, string txttieude, string txtnoidung)
        {
            DaoCuModels daocuMd = new DaoCuModels();
            DaoCu daocu = new DaoCu();
            daocu.MaVatPham = dsvp;
            daocu.Soluong = soluong;
            daocu.Trangthai = trangthai;
            daocu.Mathanhvien = dstv;
            daocuMd.TaoDaoCu(daocu);
            //if (daocuMd.KiemTraEmail(mailTo))
            //{
            string mailFrom = "h.thuhy@gmail.com";
            string pass = "nguyenthithuit";
            string port = "587";
            string host = "smtp.gmail.com";
            //  bool enableSsl = true;
            daocuMd.SendMailFull(mailFrom, pass, host, port, txtguiden, txttieude, txtnoidung, true);
            //    return RedirectToAction("Guithanhcong");
            //}
            //else
            //{
            //    ViewData["loi"] = "Mail không tồn tại";
            //}
            return View();

        }
        #region
        [HttpGet]
        public ActionResult SendMail()
        {
            return View();
        }
        [HttpPost]
        public ActionResult SendMail(string mailTo, string subject, string content)
        {
           DaoCuModels DaocuMd = new DaoCuModels();

           if (DaocuMd.KiemTraEmail(mailTo))
            {
                string mailFrom = "h.thuhy@gmail.com";
                string pass = "nguyenthithuit";
                string port = "587";
                string host = "smtp.gmail.com";
                //  bool enableSsl = true;
                DaocuMd.SendMailFull(mailFrom, pass, host, port, mailTo, subject, content, true);
                return RedirectToAction("Guithanhcong");
            }
            else
            {
                ViewData["loi"] = "Mail không tồn tại";
            }
            return View();


        }
        #endregion

        public ActionResult Layds()
        {
            VatPhamModels VpMd = new VatPhamModels();
            List<VatPham> dsvp = new List<VatPham>();
            dsvp = VpMd.LayVatPham();
            ViewData["dsvp"] = new SelectList(VpMd.LayVatPham(), "MaVatPham", "TenVatPham");
            return View();
        }

    }
}
